import { getSymbolSimpleDetail } from "./utils";
import marketCategory from "utils/market";
import { store } from "store";
//得到标准时区的时间的函数
function GetLocalTime(i) {
  if (typeof i !== "number") {
    return;
  }
  let d = new Date(),
    //得到1970年一月一日到现在的秒数
    len = d.getTime(),
    //本地时间与GMT时间的时间偏移差
    offset = d.getTimezoneOffset() * 60000,
    //得到现在的格林尼治时间
    utcTime = len + offset;
  return new Date(utcTime + 3600000 * i);
}
let g_NYMEXTimeData,
  g_COMEXTimeData,
  g_NYBOTTimeData,
  g_CBOTTimeData,
  g_LMETimeData,
  g_FuturesTimeData,
  SHStock_market = marketCategory.find((res) => {
    return res.category === 1010;
  }).marketCodes, // 上海市场股票
  SZStock_market = marketCategory.find((res) => {
    return res.category === 1020;
  }).marketCodes, // 深圳市场股票
  // 期权
  ShareOption_market = [
    ...marketCategory.find((res) => {
      return res.category === 3010;
    }).marketCodes, // 个股期权
  ],
  GoodsOption_market = [
    ...marketCategory.find((res) => {
      return res.category === 3020;
    }).marketCodes, // 商品期权
  ],
  DBond_market = [
    ...marketCategory.find((res) => {
      return res.category === 5010;
    }).marketCodes,
  ], // 新债
  BjConvertibleBond_market = [
    // 北交所可转债
    ...marketCategory.find((res) => {
      return res.category === 5030;
    }).marketCodes,
  ],
  HSIndex_market = [
    ...marketCategory.find((res) => {
      return res.category === 6000;
    }).marketCodes,
  ], //沪深指数
  HKIndex_market = [
    ...marketCategory.find((res) => {
      return res.category === 6010;
    }).marketCodes,
  ], // 香港指数
  GlobalIndex_market = [
    ...marketCategory.find((res) => {
      return res.category === 6020;
    }).marketCodes,
  ], //全球指数
  PlateIndex_market = [
    ...marketCategory.find((res) => {
      return res.category === 6030;
    }).marketCodes,
  ], // 板块指数
  Futures_market = [
    ...marketCategory.find((res) => {
      return res.category === 2000;
    }).marketCodes,
    ...marketCategory.find((res) => {
      return res.category === 2010;
    }).marketCodes,
    ...marketCategory.find((res) => {
      return res.category === 2020;
    }).marketCodes,
  ], // 期货市场集合
  CFFEX_market = [
    ...marketCategory.find((res) => {
      return res.category === 2010;
    }).marketCodes,
  ], // 中证商品指数 - 中金所国债期货
  CITICS_market = [
    ...marketCategory.find((res) => {
      return res.category === 2020;
    }).marketCodes,
  ], // 中证商品指数 - 中金所国债期货
  ChinaFutures_market = [
    ...marketCategory.find((res) => {
      return res.category === 2030;
    }).marketCodes,
  ], // 国内期货
  Foreign_market = [
    ...marketCategory.find((res) => {
      return res.category === 7000;
    }).marketCodes,
    ...marketCategory.find((res) => {
      return res.category === 7010;
    }).marketCodes,
    ...marketCategory.find((res) => {
      return res.category === 7020;
    }).marketCodes,
    ...marketCategory.find((res) => {
      return res.category === 7030;
    }).marketCodes,
    ...marketCategory.find((res) => {
      return res.category === 7050;
    }).marketCodes,
    ...marketCategory.find((res) => {
      return res.category === 7060;
    }).marketCodes,
    ...marketCategory.find((res) => {
      return res.category === 7070;
    }).marketCodes,
    ...marketCategory.find((res) => {
      return res.category === 7080;
    }).marketCodes,
  ], // 外汇市场集合
  ForeignForward_matket = [
    ...marketCategory.find((res) => {
      return res.category === 7010;
    }).marketCodes,
  ], //外汇远期市场
  InterbankRMBI_market = [
    ...marketCategory.find((res) => {
      return res.category === 7050;
    }).marketCodes,
  ],
  GlobalForeign_market = [
    ...marketCategory.find((res) => {
      return res.category === 7040;
    }).marketCodes,
  ],
  InterbankBondIndex_market = [
    ...marketCategory.find((res) => {
      return res.category === 8000;
    }).marketCodes,
  ],
  Interbank_bond_market = [
    ...marketCategory.find((res) => {
      return res.category === 8010;
    }).marketCodes,
  ],
  Interbank_rate_market = [
    ...marketCategory.find((res) => {
      return res.category === 8020;
    }).marketCodes,
  ],
  Interbank_repo_market = [
    ...marketCategory.find((res) => {
      return res.category === 8030;
    }).marketCodes,
  ],
  Interbank_forward_market = [
    ...marketCategory.find((res) => {
      return res.category === 8040;
    }).marketCodes,
  ],
  cacheStockDetail = {}, // 代码详细信息 缓存
  MARKET_SUFFIX_NAME = {
    SH: ".SS",
    SZ: [".SZ", ".XSHE"],
    SHO: ".SHO", //上海交易所 股票期权
    HK: ".HK", //港股
    FHK: ".FHK", //港股期货
    SHFE: ".SHF", //上期所 (Shanghai Futures Exchange)
    SHFE2: ".SHFE", //上期所 (Shanghai Futures Exchange)
    CFFEX: ".CCFX", //中期所 (China Financial Futures Exchange)
    DCE: ".XDCE", //大连商品交易所(Dalian Commodity Exchange)
    CZCE: ".CZC", //郑州期货交易所
    USA: ".USA", //美股
    FTSE: ".FTSE", //富时中国

    BIT: ".BIT", //数字货币 如比特币
    BIZ: ".BIZ", //数字货币

    FXCFES: ".FXCFES", //外汇 (Foreign Exchange)

    NYMEX: ".NYMEX", //纽约商品期货交易所(New York Mercantile Exchange)
    COMEX: ".COMEX", //纽约商品期货交易所(New York Mercantile Exchange)
    NYBOT: ".NYBOT", //美國紐約商品交易所
    CBOT: ".CBOT", //芝商所

    LME: ".LME", //伦敦金属交易所

    ET: ".ET", //其他未知的品种
    IsET(upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.ET) > 0;
    },

    IsETShowAvPrice() {
      return false;
    },

    IsNYMEX(upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.NYMEX) > 0;
    },

    IsCOMEX: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.COMEX) > 0;
    },

    IsNYBOT: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.NYBOT) > 0;
    },

    IsCBOT: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.CBOT) > 0;
    },

    IsLME: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.LME) > 0;
    },
    // 是否是国际外汇
    IsGlobalForeignCurrency(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (GlobalForeign_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    // 是否是外汇
    IsForeignCurrency(upperSymbol, stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}${
          stockCodeKey.hq_type_code ? "." + stockCodeKey.hq_type_code : ""
        }`;
        if (Foreign_market.includes(item)) {
          return true;
        }
        return false;
      } else {
        if (!upperSymbol) {
          return false;
        }
        return upperSymbol.indexOf(this.FXCFES) > 0;
      }
    },
    // 是否是外汇远期
    IsForeignForward(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (ForeignForward_matket.includes(item)) {
          return true;
        }
      }
      return false;
    },
    // 是否是债券
    IsBond(stockCodeKey) {
      return (
        this.IsForeignBond(stockCodeKey) ||
        this.IsInterbankBond(stockCodeKey) ||
        this.IsInterbankRate(stockCodeKey) ||
        this.IsInterbankRepo(stockCodeKey) ||
        this.IsInterbankBondIndex(stockCodeKey)
      );
    },
    // 北交所可转债
    IsBjConvertibleBond(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (BjConvertibleBond_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    // 新债
    IsDBond(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (DBond_market.includes(item)) {
          return false;
        }
      }
      return false;
    },
    // 是否是外汇债券(bondcfes)
    IsForeignBond(stockCodeKey) {
      if (stockCodeKey) {
        if (stockCodeKey.finance_mic === "BONDCFES") {
          return true;
        }
      }
      return false;
    },
    // 是否是银行间债券
    IsInterbankBond(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (Interbank_bond_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    // 是否是银行间利率
    IsInterbankRate(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (Interbank_rate_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    // 是否是银行间汇率指数
    IsInterbankRMBI(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (InterbankRMBI_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    // 是否是银行间债券指数
    IsInterbankBondIndex(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (InterbankBondIndex_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    // 是否是银行间债券远期
    IsInterbankBondForward(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (Interbank_forward_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    IsInterbankRepo(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (Interbank_repo_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    IsFTSE: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.FTSE) > 0;
    },

    IsFHK: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.FHK) > 0;
    },

    IsBIT: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      if (upperSymbol.indexOf(this.BIT) > 0) {
        return true;
      }
      if (upperSymbol.indexOf(this.BIZ) > 0) {
        return true;
      }
      return false;
    },
    //是否是美股
    IsUSA: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.USA) > 0;
    },
    // 上海股票
    IsSH: function (symbol, type) {
      if (type) {
        const item = `${symbol.split(".")[1]}.${type}`;
        if (SHStock_market.includes(item)) {
          return true;
        }
        return false;
      } else if (symbol) {
        return (
          symbol.endsWith("SS") ||
          symbol.endsWith("XBHS") ||
          symbol.endsWith("XSHG")
        );
      }
      return false;
    },
    // 深圳股票
    IsSZ: function (upperSymbol, type) {
      if (type) {
        const item = `${upperSymbol.split(".")[1]}.${type}`;
        if (SZStock_market.includes(item)) {
          return true;
        }
        return false;
      } else if (upperSymbol) {
        return upperSymbol.endsWith("SZ") || upperSymbol.endsWith("XSHE");
        // let pos = upperSymbol.length - this.SZ.length,
        //   find = upperSymbol.indexOf(this.SZ);
        // return find === pos;
      }
      return false;
    },

    IsSHO: function (upperSymbol) {
      let pos = upperSymbol.length - this.SHO.length,
        find = upperSymbol.indexOf(this.SHO);
      return find === pos;
    },

    IsHK: function (upperSymbol) {
      let pos = upperSymbol.length - this.HK.length,
        find = upperSymbol.indexOf(this.HK);
      return find === pos;
    },

    IsSHFE: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      if (upperSymbol.indexOf(this.SHFE) > 0) {
        return true;
      }
      if (upperSymbol.indexOf(this.SHFE2) > 0) {
        return true;
      }
      return false;
    },

    IsCFFEX: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      if (upperSymbol.indexOf(this.CFFEX) > 0) {
        return true;
      }

      return false;
    },

    IsDCE: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.DCE) > 0;
    },

    IsCZCE: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      return upperSymbol.indexOf(this.CZCE) > 0;
    },
    //是否是国内期货
    IsChinaFutures: function (upperSymbol) {
      return (
        this.IsCFFEX(upperSymbol) ||
        this.IsCZCE(upperSymbol) ||
        this.IsDCE(upperSymbol) ||
        this.IsSHFE(upperSymbol)
      );
    },
    IsChinaFuturesV2: (stockCodeKey) => {
      //国内期货
      const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
      if (ChinaFutures_market.includes(item)) {
        return true;
      }
      return false;
    },
    IsFutures(
      upperSymbol, //是否是期货 包含国外的
      stockCodeKey
    ) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}`;
        if (Futures_market.includes(item)) {
          return true;
        }
        return false;
      } else {
        return (
          this.IsChinaFutures(upperSymbol) ||
          this.IsNYMEX(upperSymbol) ||
          this.IsCOMEX(upperSymbol) ||
          this.IsNYBOT(upperSymbol) ||
          this.IsCBOT(upperSymbol) ||
          this.IsLME(upperSymbol)
        );
      }
    },
    IsCCICFFEX(stockCodeKey) {
      //中证商品指数 - 中金所国债期货
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (CFFEX_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    IsCCICITICS(stockCodeKey) {
      //中证商品指数 - 中信国债期货
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (CITICS_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    // 是否是期权
    IsOption(stockCodeKey) {
      return (
        this.IsShareOption(stockCodeKey) || this.IsGoodsOption(stockCodeKey)
      );
    },
    // 个股期权
    IsShareOption(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (ShareOption_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    // 商品期权
    IsGoodsOption(stockCodeKey) {
      if (stockCodeKey) {
        const item = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
        if (GoodsOption_market.includes(item)) {
          return true;
        }
      }
      return false;
    },
    //是否是沪深的股票
    IsSHSZ: function (upperSymbol, type) {
      return this.IsSZ(upperSymbol, type) || this.IsSH(upperSymbol, type);
    },
    IsFund: function (stockCodeKey) {
      // 是否是公募基金
      if (stockCodeKey) {
        if (stockCodeKey.finance_mic === "OF") {
          return true;
        }
      }
      return false;
    },
    IsCurrencyFund: function (stockCodeKey) {
      // 是否是 货币型场外基金
      if (stockCodeKey) {
        if (stockCodeKey.finance_mic === "OF") {
          const code = `${stockCodeKey.prod_code}.${stockCodeKey.finance_mic}`;
          const currencyFundCache = store.state.common.currencyFundCache;
          if (currencyFundCache[code]) {
            return (
              currencyFundCache[code] === 1 || currencyFundCache[code] === 2
            );
          }
          return new Promise((resolve) => {
            ucf.api.fin.quote
              .getFundType({
                GilCode: code,
                ApiName: "FT.Fundamentals.Fund.FundType",
                WriteType: "json2",
                Compress: "false",
              })
              .then((res) => {
                try {
                  const isCurrency =
                    res.data.rows[0].fundtypecode === 1 ||
                    res.data.rows[0].fundtypecode === 2;
                  store.dispatch("updateCurrencyFundCache", {
                    key: code,
                    value: res.data.rows[0].fundtypecode,
                  });
                  resolve(isCurrency);
                } catch (e) {
                  resolve(false);
                }
              })
              .catch(() => {
                resolve(false);
              });
          });
        }
        return false;
      }
      return false;
    },
    //是否是交易所基金
    IsSHSZFund: function (upperSymbol) {
      if (!upperSymbol) {
        return false;
      }
      //51XXXX.SH
      if (this.IsSH(upperSymbol)) {
        if (upperSymbol.charAt(0) === "5" && upperSymbol.charAt(1) === "1") {
          return true;
        }
      } else if (this.IsSZ(upperSymbol)) {
        //15XXXX.sz, 16XXXX.sz, 17XXXX.sz, 18XXXX.sz
        if (
          upperSymbol.charAt(0) === "1" &&
          (upperSymbol.charAt(1) === "5" ||
            upperSymbol.charAt(1) === "6" ||
            upperSymbol.charAt(1) === "7" ||
            upperSymbol.charAt(1) === "8")
        ) {
          return true;
        }
      }

      return false;
    },
    // 是否是科创板或创业板
    isKechuangOrChuangye: function (stockCodeKey) {
      const marketCode = `${stockCodeKey.finance_mic}.${stockCodeKey.hq_type_code}`;
      return ["XSHG.KSH", "XSHE.ESA.GEM"].includes(marketCode);
    },
    IsIndex: function (symbol, type) {
      if (!symbol) {
        return false;
      }
      let item = null;
      if (type) {
        let dotIndex = symbol.lastIndexOf(".");
        item = `${symbol.slice(dotIndex + 1)}.${type}`;
      } else {
        if (cacheStockDetail[symbol]) {
          item = cacheStockDetail[symbol];
        } else {
          const stock = getSymbolSimpleDetail(symbol);
          cacheStockDetail[symbol] = stock;
          item = `${stock.finance_mic}.${stock.hq_type_code}`;
        }
      }
      if (
        this.IsHSIndex(item) ||
        this.IsHKIndex(item) ||
        this.IsGlobalIndex(item) ||
        this.IsPlateIndex(item)
      ) {
        return true;
      }
      return false;
    },
    //是否是沪深指数代码(对接本地配置config)
    IsHSIndex: function (symbol) {
      if (HSIndex_market.includes(symbol)) {
        return true;
      }
      return false;
    },
    // 香港指数
    IsHKIndex: function (symbol) {
      if (HKIndex_market.includes(symbol)) {
        return true;
      }
      return false;
    },
    // 全球指数
    IsGlobalIndex: function (symbol) {
      if (GlobalIndex_market.includes(symbol)) {
        return true;
      }
      return false;
    },
    // 板块指数
    IsPlateIndex: function (symbol) {
      if (PlateIndex_market.includes(symbol)) {
        return true;
      }
      return false;
    },
    //是否是沪深指数代码(之前逻辑)
    IsSHSZIndex: function (symbol) {
      if (!symbol) {
        return false;
      }
      let upperSymbol = symbol.toUpperCase();
      if (this.IsSH(upperSymbol)) {
        let temp = upperSymbol.replace(".SH", "");
        if (upperSymbol.charAt(0) === "0" && parseInt(temp) <= 3000) {
          return true;
        }
      } else if (this.IsSZ(upperSymbol)) {
        if (upperSymbol.charAt(0) === "3" && upperSymbol.charAt(1) === "9") {
          return true;
        }
      } else if (upperSymbol.indexOf(".CI") > 0) {
        return true;
      }

      return false;
    },
    //是否是沪深A股
    IsSHSZStockA: function (symbol) {
      if (!symbol) {
        return false;
      }
      let upperSymbol = symbol.toUpperCase();
      if (this.IsSH(upperSymbol) && upperSymbol.charAt(0) === "6") {
        return true;
      } else if (this.IsSZ(upperSymbol)) {
        if (upperSymbol.charAt(0) === "0") {
          if (upperSymbol.charAt(1) === "0" && upperSymbol.charAt(2) === "2") {
            return true;
          } //002 中小板
          if (upperSymbol.charAt(1) !== "7" && upperSymbol.charAt(1) !== "8") {
            return true;
          }
        }
      }
    },
    //是否是沪深B股
    IsSHSZStockB: function (symbol) {
      // 未写完 先别用
      if (!symbol) {
        return false;
      }
      let upperSymbol = symbol.toUpperCase();
      if (this.IsSH(upperSymbol) && upperSymbol.charAt(0) === "9") {
        return true;
      }
    },
    // 是否是科创板 Sci-Tech innovAtion boaRd (STAR Market)
    IsSHStockSTAR: function (symbol) {
      if (!symbol) {
        return false;
      }
      let upperSymbol = symbol.toUpperCase();
      if (!this.IsSH(upperSymbol)) {
        return false;
      }
      if (
        upperSymbol.charAt(0) === "6" &&
        upperSymbol.charAt(1) === "8" &&
        upperSymbol.charAt(2) === "8"
      ) {
        return true;
      }
      return false;
    },

    GetMarketStatus: function (
      symbol //获取市场状态 0=闭市 1=盘前 2=盘中 3=盘后
    ) {
      if (!symbol) {
        return 0;
      }
      let upperSymbol = symbol.toUpperCase(),
        nowDate = new Date(),
        day = nowDate.getDay(),
        time = nowDate.getHours() * 100 + nowDate.getMinutes();
      if (this.IsUSA(upperSymbol)) {
        let usaDate = GetLocalTime(-4),
          day = usaDate.getDay(),
          time = usaDate.getHours() * 100 + usaDate.getMinutes();
        if (day === 6 || day === 0) {
          return 0;
        } //周末

        //9:30 - 16:00 考虑夏令时间时间增加1小时 9:30 - 17:00
        if (time > 1730) {
          return 3;
        }
        if (time < 930) {
          return 1;
        }

        return 2;
        //数字货币24小时
      } else if (this.IsBIT(upperSymbol)) {
        return 2;
        //外汇24小时
      } else if (this.IsForeignCurrency(upperSymbol)) {
        return 2;
        //富时中国 9:00-16:30 17:00-04:45
      } else if (this.IsFTSE(upperSymbol)) {
        if (day === 6 || day === 0) {
          return 0;
        } //周末
        if (time >= 830 && time <= 2359) {
          return 2;
        }
        if (time >= 0 && time <= 500) {
          return 2;
        }
        return 0;
        //港股指数期货 9:15-12:00 13:00-16:30 17:15-01:00
      } else if (this.IsFHK(upperSymbol)) {
        if (day === 6 || day === 0) {
          return 0;
        } //周末
        if (time >= 900 && time <= 2359) {
          return 2;
        }
        if (time >= 0 && time <= 320) {
          return 2;
        }
        return 0;
      } else if (this.IsET(upperSymbol)) {
        return this.GetETMarketStatus(symbol);
        //港股
      } else if (this.IsHK(upperSymbol)) {
        if (day === 6 || day === 0) {
          return 0;
        } //周末
        if (time > 1630) {
          return 3;
        }
        if (time < 925) {
          return 1;
        }
        return 2;
      } else if (this.IsNYMEX(upperSymbol)) {
        return this.GetNYMEXMarketStatus(upperSymbol);
      } else if (this.IsCOMEX(upperSymbol)) {
        return this.GetCOMEXMarketStatus(upperSymbol);
      } else if (this.IsNYBOT(upperSymbol)) {
        return this.GetNYBOTMarketStatus(upperSymbol);
      } else if (this.IsCBOT(upperSymbol)) {
        return this.GetCBOTMarketStatus(upperSymbol);
      } else if (this.IsLME(upperSymbol)) {
        return this.GetLMEMarketStatus(upperSymbol);
        //9:30 - 15:40
      } else {
        if (day === 6 || day === 0) {
          return 0;
        } //周末
        if (time > 1540) {
          return 3;
        }
        if (time < 925) {
          return 1;
        }
        return 2;
      }
    },
    //涨停范围
    GetLimitPriceRange: function (symbol, name) {
      if (!this.IsSHSZStockA(symbol)) {
        return null;
      }
      if (this.IsSHStockSTAR(symbol)) {
        return {
          Max: 0.2,
          Min: -0.2,
        };
      } //科创板 [20%- -20%]

      if (!name) {
        return null;
      }
      if (name.indexOf("ST") >= 0) {
        return {
          Max: 0.05,
          Min: -0.05,
        };
      } //ST 股票 [5% - -5%]

      return {
        Max: 0.1,
        Min: -0.1,
      }; //[10% - -10%]
    },
    //港股指数期货 小数位数
    GetFHKDecimal: function () {
      return 0;
    },
    //富时中国A50期货 小数位数
    GetFTSEDecimal: function () {
      return 0;
    },

    GetBITDecimal: function () {
      return 2;
    },

    GetSHODecimal: function () {
      return 4;
    },

    GetETDecimal: function () {
      return 2;
    },
    // 大连期货
    GetDCEDecimal: function () {
      return 0;
    },

    GetForeignExchangeDecimal: function () {
      return 4;
    },
    //纽约期货交易所
    GetNYMEXDecimal: function (symbol) {
      return g_NYMEXTimeData.GetDecimal(symbol);
    },

    GetCOMEXDecimal: function (symbol) {
      return g_COMEXTimeData.GetDecimal(symbol);
    },

    GetNYBOTDecimal: function (symbol) {
      return g_NYBOTTimeData.GetDecimal(symbol);
    },

    GetCBOTDecimal: function (symbol) {
      return g_CBOTTimeData.GetDecimal(symbol);
    },

    GetLMEDecimal: function (symbol) {
      return g_LMETimeData.GetDecimal(symbol);
    },

    GetETMarketStatus: function () {
      // 0=闭市 1=盘前 2=盘中 3=盘后
      return 2;
    },

    GetNYMEXMarketStatus: function (symbol) {
      return g_NYMEXTimeData.GetMarketStatus(symbol);
    },

    GetCOMEXMarketStatus: function (symbol) {
      return g_COMEXTimeData.GetMarketStatus(symbol);
    },

    GetNYBOTMarketStatus: function (symbol) {
      return g_NYBOTTimeData.GetMarketStatus(symbol);
    },

    GetCBOTMarketStatus: function (symbol) {
      return g_CBOTTimeData.GetMarketStatus(symbol);
    },

    GetLMEMarketStatus: function (symbol) {
      return g_LMETimeData.GetMarketStatus(symbol);
    },
  };
function NYMEXTimeData() {
  //美国标准时间
  this.TIME_SPLIT = [
    {
      Name: "6:00-5:00",
      Data: [
        //6:00 - 5:00
        {
          Start: 600,
          End: 2359,
        },
        {
          Start: 0,
          End: 500,
        },
      ],
      Coordinate: {
        //完整模式
        Full: [
          {
            Value: 600,
            Text: "6:00",
          },
          {
            Value: 800,
            Text: "8:00",
          },
          {
            Value: 1000,
            Text: "10:00",
          },
          {
            Value: 1200,
            Text: "12:00",
          },
          {
            Value: 1400,
            Text: "14:00",
          },
          {
            Value: 1600,
            Text: "16:00",
          },
          {
            Value: 1800,
            Text: "18:00",
          },
          {
            Value: 2000,
            Text: "20:00",
          },
          {
            Value: 2200,
            Text: "22:00",
          },
          {
            Value: 0,
            Text: "0:00",
          },
          {
            Value: 200,
            Text: "2:00",
          },
          {
            Value: 400,
            Text: "4:00",
          },
        ],
        //简洁模式
        Simple: [
          {
            Value: 600,
            Text: "6:00",
          },
          //{ Value: 800, Text: '8:00' },
          {
            Value: 1000,
            Text: "10:00",
          },
          //{ Value: 1200, Text: '12:00' },
          {
            Value: 1400,
            Text: "14:00",
          },
          //{ Value: 1600, Text: '16:00' },
          {
            Value: 1800,
            Text: "18:00",
          },
          //{ Value: 2000, Text: '20:00' },
          {
            Value: 2200,
            Text: "22:00",
          },
          //{ Value: 0, Text: '0:00' },
          {
            Value: 200,
            Text: "2:00",
          },
          //{ Value: 400, Text: '4:00' },
        ],
        //最小模式
        Min: [
          {
            Value: 600,
            Text: "6:00",
          },
          {
            Value: 1800,
            Text: "18:00",
          },
          {
            Value: 500,
            Text: "5:00",
          },
        ],
      },
    },
  ];

  //美国夏时令
  this.TIME_SPLIT2 = [
    {
      Name: "7:00-6:00",
      Data: [
        //6:00 - 5:00
        {
          Start: 700,
          End: 2359,
        },
        {
          Start: 0,
          End: 600,
        },
      ],
      Coordinate: {
        //完整模式
        Full: [
          {
            Value: 700,
            Text: "7:00",
          },
          {
            Value: 900,
            Text: "9:00",
          },
          {
            Value: 1100,
            Text: "11:00",
          },
          {
            Value: 1300,
            Text: "13:00",
          },
          {
            Value: 1500,
            Text: "15:00",
          },
          {
            Value: 1700,
            Text: "17:00",
          },
          {
            Value: 1900,
            Text: "19:00",
          },
          {
            Value: 2100,
            Text: "21:00",
          },
          {
            Value: 2300,
            Text: "23:00",
          },
          {
            Value: 1,
            Text: "1:00",
          },
          {
            Value: 300,
            Text: "3:00",
          },
          {
            Value: 500,
            Text: "5:00",
          },
        ],
        //简洁模式
        Simple: [
          {
            Value: 700,
            Text: "7:00",
          },
          //{ Value: 900, Text: '9:00' },
          {
            Value: 1100,
            Text: "11:00",
          },
          //{ Value: 1300, Text: '13:00' },
          {
            Value: 1500,
            Text: "15:00",
          },
          //{ Value: 1700, Text: '17:00' },
          {
            Value: 1900,
            Text: "19:00",
          },
          //{ Value: 2100, Text: '21:00' },
          {
            Value: 2300,
            Text: "23:00",
          },
          //{ Value: 1, Text: '1:00' },
          {
            Value: 300,
            Text: "3:00",
          },
          //{ Value: 500, Text: '5:00' }
        ],
        //最小模式
        Min: [
          {
            Value: 700,
            Text: "7:00",
          },
          {
            Value: 1900,
            Text: "19:00",
          },
          {
            Value: 500,
            Text: "5:00",
          },
        ],
      },
    },
  ];

  this.FUTURES_LIST = [
    {
      Symbol: "CL",
      Decimal: 2,
      Time: 0,
    }, //原油
    {
      Symbol: "NG",
      Decimal: 3,
      Time: 0,
    }, //天然气
    {
      Symbol: "RB",
      Decimal: 4,
      Time: 0,
    }, //汽油
    {
      Symbol: "PL",
      Decimal: 1,
      Time: 0,
    }, //铂金
    {
      Symbol: "PA",
      Decimal: 2,
      Time: 0,
    }, //钯金
    {
      Symbol: "HR",
      Decimal: 0,
      Time: 0,
    }, //热轧钢卷
    {
      Symbol: "QM",
      Decimal: 3,
      Time: 0,
    }, //迷你原油
    {
      Symbol: "HO",
      Decimal: 4,
      Time: 0,
    }, //燃油
  ];

  this.MarketSuffix = ".NYMEX";
  this.TimeType = 0; // 0=标准时间 1=夏令时间 2=美国时间

  this.GetFuturesInfo = function (upperSymbol) {
    if (upperSymbol.indexOf(this.MarketSuffix) <= 0) {
      return null;
    }

    for (let i in this.FUTURES_LIST) {
      let item = this.FUTURES_LIST[i];
      if (upperSymbol.indexOf(item.Symbol) === 0) {
        return item;
      }
    }

    return null;
  };

  this.GetSplitData = function (upperSymbol) {
    //夏令和标准时间切换
    let timeSplit = this.TimeType === 0 ? this.TIME_SPLIT : this.TIME_SPLIT2,
      find = this.GetFuturesInfo(upperSymbol);
    if (find) {
      return timeSplit[find.Time];
    }

    return timeSplit[0];
  };

  this.GetDecimal = function (upperSymbol) {
    let find = this.GetFuturesInfo(upperSymbol);
    if (find) {
      return find.Decimal;
    }

    return 3;
  };
  // 0=闭市 1=盘前 2=盘中 3=盘后
  this.GetMarketStatus = function () {
    let usaDate = GetLocalTime(-4), //需要转成美国时间的 周6 周日
      nowDate = new Date(),
      day = usaDate.getDay(),
      time = nowDate.getHours() * 100 + nowDate.getMinutes();
    if (day === 6 || day === 0) {
      return 0;
    } //周末
    if (time > 430 && time < 730) {
      return 1;
    }

    return 2;
  };
}

function COMEXTimeData() {
  this.newMethod = NYMEXTimeData; //派生
  this.newMethod();
  delete this.newMethod;

  this.FUTURES_LIST = [
    { Symbol: "GC", Decimal: 1, Time: 0 }, //COMEX黄金
    { Symbol: "QO", Decimal: 2, Time: 0 }, //迷你黄金
    { Symbol: "MG", Decimal: 1, Time: 0 }, //微型黄金
    { Symbol: "QI", Decimal: 4, Time: 0 }, //迷你白银
    { Symbol: "SI", Decimal: 3, Time: 0 }, //COMEX白银
    { Symbol: "QI", Decimal: 4, Time: 0 }, //迷你白银
    { Symbol: "HG", Decimal: 4, Time: 0 }, //COMEX铜
  ];

  this.MarketSuffix = ".COMEX";
}

function NYBOTTimeData() {
  this.newMethod = NYMEXTimeData; //派生
  this.newMethod();
  delete this.newMethod;

  this.TIME_SPLIT = [
    {
      Name: "9:00-2:20",
      Data: [
        { Start: 900, End: 2359 },
        { Start: 0, End: 220 },
      ],
      Coordinate: {
        Full: [
          { Value: 900, Text: "9:00" },
          { Value: 1100, Text: "11:00" },
          { Value: 1300, Text: "13:00" },
          { Value: 1500, Text: "15:00" },
          { Value: 1700, Text: "17:00" },
          { Value: 1900, Text: "19:00" },
          { Value: 2100, Text: "21:00" },
          { Value: 2300, Text: "23:00" },
          { Value: 100, Text: "1:00" },
        ],
        Simple: [
          { Value: 900, Text: "9:00" },
          //{ Value: 1100, Text: '11:00' },
          { Value: 1300, Text: "13:00" },
          //{ Value: 1500, Text: '15:00' },
          { Value: 1700, Text: "17:00" },
          //{ Value: 1900, Text: '19:00' },
          { Value: 2100, Text: "21:00" },
          //{ Value: 2300, Text: '23:00' },
          { Value: 100, Text: "1:00" },
        ],
        Min: [
          { Value: 900, Text: "9:00" },
          { Value: 1700, Text: "17:00" },
          { Value: 100, Text: "1:00" },
        ],
      },
    },
    {
      Name: "15:30-1:00",
      Data: [
        //9:00-2:20
        { Start: 1530, End: 2359 },
        { Start: 0, End: 100 },
      ],
      Coordinate: {
        Full: [
          { Value: 1600, Text: "16:00" },
          { Value: 1700, Text: "17:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 1900, Text: "19:00" },
          { Value: 2000, Text: "20:00" },
          { Value: 2100, Text: "21:00" },
          { Value: 2200, Text: "22:00" },
          { Value: 2300, Text: "23:00" },
          { Value: 0, Text: "0:00" },
          { Value: 100, Text: "1:00" },
        ],
        Simple: [
          { Value: 1600, Text: "16:00" },
          //{ Value: 1600, Text: '17:00' },
          { Value: 1800, Text: "18:00" },
          //{ Value: 1900, Text: '19:00' },
          { Value: 2000, Text: "20:00" },
          //{ Value: 2100, Text: '21:00' },
          { Value: 2200, Text: "22:00" },
          //{ Value: 2300, Text: '23:00' },
          { Value: 0, Text: "0:00" },
          //{ Value: 100, Text: '1:00' }
        ],
        Min: [
          { Value: 1600, Text: "16:00" },
          { Value: 2100, Text: "21:00" },
          { Value: 100, Text: "1:00" },
        ],
      },
    },
  ];

  this.TIME_SPLIT2 = [
    {
      Name: "10:00-3:20",
      Data: [
        //9:00-2:20
        { Start: 1000, End: 2359 },
        { Start: 0, End: 320 },
      ],
      Coordinate: {
        Full: [
          { Value: 1000, Text: "10:00" },
          { Value: 1200, Text: "12:00" },
          { Value: 1400, Text: "14:00" },
          { Value: 1600, Text: "16:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 2000, Text: "20:00" },
          { Value: 2200, Text: "22:00" },
          { Value: 0, Text: "0:00" },
          { Value: 200, Text: "2:00" },
        ],
        Simple: [
          { Value: 1000, Text: "10:00" },
          //{ Value: 1200, Text: '12:00' },
          { Value: 1400, Text: "14:00" },
          //{ Value: 1600, Text: '16:00' },
          { Value: 1800, Text: "18:00" },
          //{ Value: 2000, Text: '20:00' },
          { Value: 2200, Text: "22:00" },
          //{ Value: 0, Text: '0:00' },
          { Value: 200, Text: "2:00" },
        ],
        Min: [
          { Value: 1000, Text: "10:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 200, Text: "2:00" },
        ],
      },
    },
    {
      Name: "16:30-2:00",
      Data: [
        { Start: 1630, End: 2359 },
        { Start: 0, End: 200 },
      ],
      Coordinate: {
        Full: [
          { Value: 1700, Text: "17:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 1900, Text: "19:00" },
          { Value: 2000, Text: "20:00" },
          { Value: 2100, Text: "21:00" },
          { Value: 2200, Text: "22:00" },
          { Value: 2300, Text: "23:00" },
          { Value: 0, Text: "0:00" },
          { Value: 100, Text: "1:00" },
          { Value: 200, Text: "2:00" },
        ], //简洁模式
        Simple: [
          { Value: 1700, Text: "17:00" },
          //{ Value: 1800, Text: '18:00' },
          { Value: 1900, Text: "19:00" },
          //{ Value: 2000, Text: '20:00' },
          { Value: 2100, Text: "21:00" },
          //{ Value: 2200, Text: '22:00' },
          { Value: 2300, Text: "23:00" },
          //{ Value: 0, Text: '0:00' },
          { Value: 100, Text: "1:00" },
          //{ Value: 200, Text: '2:00' }
        ], //最小模式
        Min: [
          { Value: 1700, Text: "17:00" },
          { Value: 2100, Text: "21:00" },
          { Value: 200, Text: "2:00" },
        ],
      },
    },
  ];

  this.FUTURES_LIST = [
    { Symbol: "SB", Decimal: 2, Time: 1 }, //11号白糖
    { Symbol: "CT", Decimal: 2, Time: 0 }, //棉花
    //{ Symbol:"KC", Decimal:2, Time:0 }, //咖啡
    //{ Symbol:"DX", Decimal:2, Time:0 }, //美元指数
    //{ Symbol:"CC", Decimal:2, Time:0 }  //可可
  ];

  this.MarketSuffix = ".NYBOT";

  this.GetMarketStatus = function (
    upperSymbol // 0=闭市 1=盘前 2=盘中 3=盘后
  ) {
    let usaDate = GetLocalTime(-4), //需要转成美国时间的 周6 周日
      day = usaDate.getDay(),
      time = usaDate.getHours() * 100 + usaDate.getMinutes(),
      find;
    if (day === 6 || day === 0) {
      return 0;
    } //周末

    find = this.GetFuturesInfo(upperSymbol);
    if (!find) {
      return 2;
    }

    if (find.Symbol === "SB") {
      //Sugar No. 11 Futures 03:30 - 13:00
      if (time > 300 && time < 1400) {
        return 2;
      }
    } else if (find.Symbol === "CT") {
      //美棉 21:00-14:20
      if ((time >= 0 && time <= 1500) || (time >= 2000 && time <= 2359)) {
        return 2;
      }
      return 1;
    }

    return 0;
  };
}
function CBOTTimeData() {
  this.newMethod = NYMEXTimeData; //派生
  this.newMethod();
  delete this.newMethod;

  //夏令时间
  this.TIME_SPLIT = [
    {
      Name: "8:00-2:20",
      Data: [
        { Start: 800, End: 2359 },
        { Start: 0, End: 220 },
      ],
      Coordinate: {
        Full: [
          { Value: 800, Text: "8:00" },
          { Value: 1000, Text: "10:00" },
          { Value: 1200, Text: "12:00" },
          { Value: 1400, Text: "14:00" },
          { Value: 1600, Text: "16:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 2000, Text: "20:00" },
          { Value: 2200, Text: "22:00" },
          { Value: 0, Text: "0:00" },
          { Value: 200, Text: "2:00" },
        ],
        Simple: [
          { Value: 800, Text: "8:00" },
          //{ Value: 1000, Text: '10:00' },
          { Value: 1200, Text: "12:00" },
          //{ Value: 1400, Text: '14:00' },
          { Value: 1600, Text: "16:00" },
          //{ Value: 1800, Text: '18:00' },
          { Value: 2000, Text: "20:00" },
          //{ Value: 2200, Text: '22:00' },
          { Value: 0, Text: "0:00" },
          //{ Value: 200, Text: '2:00' }
        ],
        Min: [
          { Value: 800, Text: "8:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 200, Text: "2:00" },
        ],
      },
    },
    {
      Name: "8:00-2:45",
      Data: [
        { Start: 800, End: 2359 },
        { Start: 0, End: 245 },
      ],
      Coordinate: {
        Full: [
          { Value: 800, Text: "8:00" },
          { Value: 1000, Text: "10:00" },
          { Value: 1200, Text: "12:00" },
          { Value: 1400, Text: "14:00" },
          { Value: 1600, Text: "16:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 2000, Text: "20:00" },
          { Value: 2200, Text: "22:00" },
          { Value: 0, Text: "0:00" },
          { Value: 200, Text: "2:00" },
        ],
        Simple: [
          { Value: 800, Text: "8:00" },
          //{ Value: 1000, Text: '10:00' },
          { Value: 1200, Text: "12:00" },
          //{ Value: 1400, Text: '14:00' },
          { Value: 1600, Text: "16:00" },
          //{ Value: 1800, Text: '18:00' },
          { Value: 2000, Text: "20:00" },
          //{ Value: 2200, Text: '22:00' },
          { Value: 0, Text: "0:00" },
          //{ Value: 200, Text: '2:00' }
        ],
        Min: [
          { Value: 800, Text: "8:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 200, Text: "2:00" },
        ],
      },
    },
    {
      Name: "6:00-5:00",
      Data: [
        { Start: 600, End: 2359 },
        { Start: 0, End: 500 },
      ],
      Coordinate: {
        Full: [
          { Value: 600, Text: "6:00" },
          { Value: 800, Text: "8:00" },
          { Value: 1000, Text: "10:00" },
          { Value: 1200, Text: "12:00" },
          { Value: 1400, Text: "14:00" },
          { Value: 1600, Text: "16:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 2000, Text: "20:00" },
          { Value: 2200, Text: "22:00" },
          { Value: 0, Text: "0:00" },
          { Value: 200, Text: "2:00" },
          { Value: 400, Text: "4:00" },
        ],
        Simple: [
          { Value: 600, Text: "6:00" },
          //{ Value: 800, Text: '8:00' },
          { Value: 1000, Text: "10:00" },
          //{ Value: 1200, Text: '12:00' },
          { Value: 1400, Text: "14:00" },
          //{ Value: 1600, Text: '16:00' },
          { Value: 1800, Text: "18:00" },
          //{ Value: 2000, Text: '20:00' },
          { Value: 2200, Text: "22:00" },
          //{ Value: 0, Text: '0:00' },
          { Value: 200, Text: "2:00" },
          //{ Value: 400, Text: '4:00' },
        ],
        Min: [
          { Value: 600, Text: "6:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 500, Text: "5:00" },
        ],
      },
    },
  ];

  //标准时间
  this.TIME_SPLIT2 = [
    {
      Name: "9:00-3:20",
      Data: [
        { Start: 900, End: 2359 },
        { Start: 0, End: 320 },
      ],
      Coordinate: {
        Full: [
          { Value: 900, Text: "9:00" },
          { Value: 1100, Text: "11:00" },
          { Value: 1300, Text: "13:00" },
          { Value: 1500, Text: "15:00" },
          { Value: 1700, Text: "17:00" },
          { Value: 1900, Text: "19:00" },
          { Value: 2100, Text: "21:00" },
          { Value: 2300, Text: "23:00" },
          { Value: 1, Text: "1:00" },
          { Value: 300, Text: "3:00" },
        ],
        Simple: [
          { Value: 900, Text: "9:00" },
          //{ Value: 1100, Text: '11:00' },
          { Value: 1300, Text: "13:00" },
          //{ Value: 1500, Text: '15:00' },
          { Value: 1700, Text: "17:00" },
          //{ Value: 1900, Text: '19:00' },
          { Value: 2100, Text: "21:00" },
          //{ Value: 2300, Text: '23:00' },
          { Value: 1, Text: "1:00" },
          //{ Value: 300, Text: '3:00' }
        ],
        Min: [
          { Value: 900, Text: "9:00" },
          { Value: 1900, Text: "19:00" },
          { Value: 300, Text: "3:00" },
        ],
      },
    },
    {
      Name: "9:00-3:45",
      Data: [
        { Start: 900, End: 2359 },
        { Start: 0, End: 345 },
      ],
      Coordinate: {
        Full: [
          { Value: 900, Text: "9:00" },
          { Value: 1100, Text: "11:00" },
          { Value: 1300, Text: "13:00" },
          { Value: 1500, Text: "15:00" },
          { Value: 1700, Text: "17:00" },
          { Value: 1900, Text: "19:00" },
          { Value: 2100, Text: "21:00" },
          { Value: 2300, Text: "23:00" },
          { Value: 1, Text: "1:00" },
          { Value: 300, Text: "3:00" },
        ],
        Simple: [
          { Value: 900, Text: "9:00" },
          //{ Value: 1100, Text: '11:00' },
          { Value: 1300, Text: "13:00" },
          //{ Value: 1500, Text: '15:00' },
          { Value: 1700, Text: "17:00" },
          //{ Value: 1900, Text: '19:00' },
          { Value: 2100, Text: "21:00" },
          //{ Value: 2300, Text: '23:00' },
          { Value: 1, Text: "1:00" },
          //{ Value: 300, Text: '3:00' }
        ],
        Min: [
          { Value: 900, Text: "9:00" },
          { Value: 1900, Text: "19:00" },
          { Value: 300, Text: "3:00" },
        ],
      },
    },
    {
      Name: "7:00-6:00",
      Data: [
        { Start: 700, End: 2359 },
        { Start: 0, End: 600 },
      ],
      Coordinate: {
        Full: [
          { Value: 700, Text: "7:00" },
          { Value: 900, Text: "9:00" },
          { Value: 1100, Text: "11:00" },
          { Value: 1300, Text: "13:00" },
          { Value: 1500, Text: "15:00" },
          { Value: 1700, Text: "17:00" },
          { Value: 1900, Text: "19:00" },
          { Value: 2100, Text: "21:00" },
          { Value: 2300, Text: "23:00" },
          { Value: 1, Text: "1:00" },
          { Value: 300, Text: "3:00" },
          { Value: 500, Text: "5:00" },
        ],
        Simple: [
          { Value: 700, Text: "7:00" },
          //{ Value: 900, Text: '9:00' },
          { Value: 1100, Text: "11:00" },
          //{ Value: 1300, Text: '13:00' },
          { Value: 1500, Text: "15:00" },
          //{ Value: 1700, Text: '17:00' },
          { Value: 1900, Text: "19:00" },
          //{ Value: 2100, Text: '21:00' },
          { Value: 2300, Text: "23:00" },
          //{ Value: 1, Text: '1:00' },
          { Value: 300, Text: "3:00" },
          //{ Value: 500, Text: '5:00' }
        ],
        Min: [
          { Value: 700, Text: "7:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 500, Text: "5:00" },
        ],
      },
    },
  ];

  this.FUTURES_LIST = [
    { Symbol: "ZC", Decimal: 2, Time: 0 }, //玉米
    { Symbol: "XC", Decimal: 2, Time: 1 }, //迷你玉米
    { Symbol: "ZS", Decimal: 2, Time: 0 }, //大豆
    { Symbol: "XK", Decimal: 2, Time: 1 }, //迷你大豆
    { Symbol: "ZL", Decimal: 2, Time: 0 }, //豆油
    { Symbol: "ZR", Decimal: 2, Time: 0 }, //稻谷
    { Symbol: "ZO", Decimal: 2, Time: 0 }, //燕麦
    { Symbol: "ZW", Decimal: 2, Time: 0 }, //小麦
    { Symbol: "XW", Decimal: 2, Time: 1 }, //迷你小麦
    { Symbol: "ZM", Decimal: 1, Time: 0 }, //豆粕

    { Symbol: "EH", Decimal: 3, Time: 2 }, //乙醇

    { Symbol: "YM", Decimal: 0, Time: 2 }, //小型道指
    { Symbol: "ES", Decimal: 2, Time: 2 }, //小型标普
    { Symbol: "NQ", Decimal: 2, Time: 2 }, //小型纳指

    { Symbol: "TY", Decimal: 4, Time: 2 }, //10年美国债
    { Symbol: "TU", Decimal: 4, Time: 2 }, //2年美国债
    { Symbol: "FV", Decimal: 4, Time: 2 }, //5年美国债
    { Symbol: "US", Decimal: 4, Time: 2 }, //30年美国债
    { Symbol: "UL", Decimal: 4, Time: 2 }, //超国债
  ];

  this.MarketSuffix = ".CBOT";
}

function LMETimeData() {
  this.newMethod = NYMEXTimeData; //派生
  this.newMethod();
  delete this.newMethod;

  //标准时间
  this.TIME_SPLIT = [
    {
      Name: "LME 9:00-3:00",
      Data: [
        { Start: 900, End: 2359 },
        { Start: 0, End: 300 },
      ],
      Coordinate: {
        Full: [
          { Value: 900, Text: "9:00" },
          { Value: 1100, Text: "11:00" },
          { Value: 1300, Text: "13:00" },
          { Value: 1500, Text: "15:00" },
          { Value: 1700, Text: "17:00" },
          { Value: 1900, Text: "19:00" },
          { Value: 2100, Text: "21:00" },
          { Value: 2300, Text: "23:00" },
          { Value: 100, Text: "1:00" },
          { Value: 300, Text: "3:00" },
        ],
        Simple: [
          { Value: 900, Text: "9:00" },
          //{ Value: 1100, Text: '11:00' },
          { Value: 1300, Text: "13:00" },
          //{ Value: 1500, Text: '15:00' },
          { Value: 1700, Text: "17:00" },
          //{ Value: 1900, Text: '19:00' },
          { Value: 2100, Text: "21:00" },
          //{ Value: 2300, Text: '23:00' },
          { Value: 100, Text: "1:00" },
          // { Value: 300, Text: '3:00' }
        ],
        Min: [
          { Value: 900, Text: "9:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 300, Text: "3:00" },
        ],
      },
    },
  ];

  //夏令
  this.TIME_SPLIT = [
    {
      Name: "LME 8:00-2:00",
      Data: [
        { Start: 800, End: 2359 },
        { Start: 0, End: 200 },
      ],
      Coordinate: {
        Full: [
          { Value: 800, Text: "8:00" },
          { Value: 1000, Text: "10:00" },
          { Value: 1200, Text: "12:00" },
          { Value: 1400, Text: "14:00" },
          { Value: 1600, Text: "16:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 2000, Text: "20:00" },
          { Value: 2200, Text: "22:00" },
          { Value: 0, Text: "0:00" },
          { Value: 200, Text: "2:00" },
        ],
        Simple: [
          { Value: 800, Text: "8:00" },
          //{ Value: 1000, Text: '10:00' },
          { Value: 1200, Text: "12:00" },
          //{ Value: 1400, Text: '14:00' },
          { Value: 1600, Text: "16:00" },
          //{ Value: 1800, Text: '18:00' },
          { Value: 2000, Text: "20:00" },
          //{ Value: 2200, Text: '22:00' },
          { Value: 0, Text: "0:00" },
          //{ Value: 200, Text: '2:00' }
        ],
        Min: [
          { Value: 800, Text: "8:00" },
          { Value: 1800, Text: "18:00" },
          { Value: 200, Text: "2:00" },
        ],
      },
    },
  ];

  this.FUTURES_LIST = [
    { Symbol: "SND", Decimal: 0, Time: 0 }, //综合锡03
    { Symbol: "AHD", Decimal: 2, Time: 0 }, //综合铝03
    { Symbol: "PBD", Decimal: 2, Time: 0 }, //综合铅03
    { Symbol: "ZSD", Decimal: 2, Time: 0 }, //综合锌03
    { Symbol: "CAD", Decimal: 2, Time: 0 }, //综合铜03
    { Symbol: "NID", Decimal: 0, Time: 0 }, //综合镍03
  ];

  this.MarketSuffix = ".LME";
}

//国内期货不同品种 交易时间数据
function FuturesTimeData() {
  const TIME_SPLIT = [
      {
        Name: "9:00-10:15,10:30-11:30,13:30-15:00",
        Data: [
          { Start: 900, End: 1015 },
          { Start: 1031, End: 1130 },
          { Start: 1331, End: 1500 },
        ],
        Coordinate: {
          Full: [
            { Value: 900, Text: "9:00" },
            { Value: 930, Text: "9:30" },
            { Value: 1000, Text: "10:00" },
            { Value: 1030, Text: "10:30" },
            { Value: 1100, Text: "11:00" },
            { Value: 1330, Text: "13:30" },
            { Value: 1400, Text: "14:00" },
            { Value: 1430, Text: "14:30" },
            { Value: 1500, Text: "15:00" },
          ],
          Simple: [
            { Value: 900, Text: "9:00" },
            { Value: 1000, Text: "10:00" },
            { Value: 1330, Text: "13:30" },
            { Value: 1430, Text: "14:30" },
            { Value: 1500, Text: "15:00" },
          ],
          Min: [
            { Value: 900, Text: "9:00" },
            { Value: 1330, Text: "13:30" },
            { Value: 1500, Text: "15:00" },
          ],
        },
      },
      {
        Name: "9:15-11:30,13:00-15:15",
        Data: [
          { Start: 915, End: 1130 },
          { Start: 1301, End: 1515 },
        ],
        Coordinate: {
          Full: [
            { Value: 930, Text: "9:30" },
            { Value: 1000, Text: "10:00" },
            { Value: 1030, Text: "10:30" },
            { Value: 1100, Text: "11:00" },
            { Value: 1300, Text: "13:00" },
            { Value: 1330, Text: "13:30" },
            { Value: 1400, Text: "14:00" },
            { Value: 1430, Text: "14:30" },
            { Value: 1515, Text: "15:15" },
          ],
          Simple: [
            { Value: 930, Text: "9:30" },
            { Value: 1030, Text: "10:30" },
            { Value: 1300, Text: "13:00" },
            { Value: 1400, Text: "14:00" },
            { Value: 1515, Text: "15:15" },
          ],
          Min: [
            { Value: 930, Text: "9:30" },
            { Value: 1300, Text: "13:00" },
            { Value: 1515, Text: "15:15" },
          ],
        },
      },
      {
        Name: "9:30-11:30,13:00-15:00",
        Data: [
          { Start: 930, End: 1130 },
          { Start: 1301, End: 1500 },
        ],
        Coordinate: {
          Full: [
            { Value: 930, Text: "9:30" },
            { Value: 1000, Text: "10:00" },
            { Value: 1030, Text: "10:30" },
            { Value: 1100, Text: "11:00" },
            { Value: 1300, Text: "13:00" },
            { Value: 1330, Text: "13:30" },
            { Value: 1400, Text: "14:00" },
            { Value: 1430, Text: "14:30" },
            { Value: 1500, Text: "15:00" },
          ],
          Simple: [
            { Value: 930, Text: "9:30" },
            { Value: 1030, Text: "10:30" },
            { Value: 1300, Text: "13:00" },
            { Value: 1400, Text: "14:00" },
            { Value: 1500, Text: "15:00" },
          ],
          Min: [
            { Value: 930, Text: "9:30" },
            { Value: 1300, Text: "13:00" },
            { Value: 1500, Text: "15:00" },
          ],
        },
      },
      {
        Name: "21:00-23:30,9:00-10:15,10:30-11:30,13:30-15:00",
        Data: [
          { Start: 2100, End: 2330 },
          { Start: 901, End: 1015 },
          { Start: 1031, End: 1130 },
          { Start: 1331, End: 1500 },
        ],
        Coordinate: {
          Full: [
            { Value: 2100, Text: "21:00" },
            { Value: 2200, Text: "22:00" },
            { Value: 2300, Text: "23:00" },
            { Value: 901, Text: "9:00" },
            { Value: 1031, Text: "10:30" },
            { Value: 1331, Text: "13:30" },
            { Value: 1430, Text: "14:30" },
            { Value: 1500, Text: "15:00" },
          ],
          Simple: [
            { Value: 2100, Text: "21:00" },
            { Value: 901, Text: "9:00" },
            { Value: 1331, Text: "13:30" },
            { Value: 1500, Text: "15:00" },
          ],
          Min: [
            { Value: 2100, Text: "21:00" },
            { Value: 901, Text: "9:00" },
            { Value: 1500, Text: "15:00" },
          ],
        },
      },
      {
        Name: "21:00-1:00,9:00-10:15,10:30-11:30,13:30-15:00",
        Data: [
          { Start: 2100, End: 2359 },
          { Start: 0, End: 100 },
          { Start: 901, End: 1015 },
          { Start: 1031, End: 1130 },
          { Start: 1331, End: 1500 },
        ],
        Coordinate: {
          Full: [
            { Value: 2100, Text: "21:00" },
            { Value: 2200, Text: "22:00" },
            { Value: 2300, Text: "23:00" },
            { Value: 901, Text: "9:00" },
            { Value: 1031, Text: "10:30" },
            { Value: 1331, Text: "13:30" },
            { Value: 1500, Text: "15:00" },
          ],
          Simple: [
            { Value: 2100, Text: "21:00" },
            { Value: 2300, Text: "23:00" },
            { Value: 901, Text: "9:00" },
            { Value: 1031, Text: "10:30" },
            { Value: 1500, Text: "15:00" },
          ],
          Min: [
            { Value: 2100, Text: "21:00" },
            { Value: 901, Text: "9:00" },
            { Value: 1500, Text: "15:00" },
          ],
        },
      },
      {
        Name: "21:00-2:30,9:00-10:15,10:30-11:30,13:30-15:00",
        Data: [
          { Start: 2100, End: 2359 },
          { Start: 0, End: 230 },
          { Start: 901, End: 1015 },
          { Start: 1031, End: 1130 },
          { Start: 1331, End: 1500 },
        ],
        Coordinate: {
          Full: [
            { Value: 2100, Text: "21:00" },
            { Value: 2300, Text: "23:00" },
            { Value: 100, Text: "1:00" },
            { Value: 901, Text: "9:00" },
            { Value: 1031, Text: "10:30" },
            { Value: 1331, Text: "13:30" },
            { Value: 1500, Text: "15:00" },
          ],
          Simple: [
            { Value: 2100, Text: "21:00" },
            { Value: 2300, Text: "23:00" },
            { Value: 901, Text: "9:00" },
            { Value: 1100, Text: "11:00" },
            { Value: 1500, Text: "15:00" },
          ],
          Min: [
            { Value: 2100, Text: "21:00" },
            { Value: 901, Text: "9:00" },
            { Value: 1500, Text: "15:00" },
          ],
        },
      },
      {
        Name: "21:00-23:00,9:00-10:15,10:30-11:30,13:30-15:00",
        Data: [
          { Start: 2100, End: 2300 },
          { Start: 901, End: 1015 },
          { Start: 1031, End: 1130 },
          { Start: 1331, End: 1500 },
        ],
        Coordinate: {
          Full: [
            { Value: 2100, Text: "21:00" },
            { Value: 2200, Text: "22:00" },
            { Value: 2300, Text: "23:00" },
            { Value: 1030, Text: "10:30" },
            { Value: 1331, Text: "13:30" },
            { Value: 1430, Text: "14:30" },
            { Value: 1500, Text: "15:00" },
          ],
          Simple: [
            { Value: 2100, Text: "21:00" },
            { Value: 2300, Text: "23:00" },
            { Value: 1331, Text: "13:30" },
            { Value: 1500, Text: "15:00" },
          ],
          Min: [
            { Value: 2100, Text: "21:00" },
            { Value: 2300, Text: "23:00" },
            { Value: 1500, Text: "15:00" },
          ],
        },
      },
    ],
    MAP_TWOWORDS = new Map([
      //大连商品交易所
      [MARKET_SUFFIX_NAME.DCE + "-JD", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.DCE + "-FB", { Time: 0, Decimal: 2 }],
      [MARKET_SUFFIX_NAME.DCE + "-BB", { Time: 0, Decimal: 2 }],
      [MARKET_SUFFIX_NAME.DCE + "-PP", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.DCE + "-JM", { Time: 3, Decimal: 1 }],
      //上期所
      [MARKET_SUFFIX_NAME.SHFE + "-CU", { Time: 4, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-AL", { Time: 4, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-NI", { Time: 4, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-SN", { Time: 4, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-ZN", { Time: 4, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-PB", { Time: 4, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-RU", { Time: 6, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-FU", { Time: 6, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-RB", { Time: 6, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-BU", { Time: 6, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-HC", { Time: 6, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-WR", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-AG", { Time: 5, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.SHFE + "-AU", { Time: 5, Decimal: 2 }],
      [MARKET_SUFFIX_NAME.SHFE + "-NR", { Time: 5, Decimal: 1 }],
      [MARKET_SUFFIX_NAME.SHFE + "-SC", { Time: 5, Decimal: 1 }],
      //郑州期货交易所
      [MARKET_SUFFIX_NAME.CZCE + "-CF", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-SR", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-MA", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-ZC", { Time: 3, Decimal: 1 }],
      [MARKET_SUFFIX_NAME.CZCE + "-TA", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-RM", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-OI", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-ME", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-FG", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-WS", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-WT", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-GN", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-RO", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-RS", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-ER", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-RI", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-WH", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-AP", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-PM", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-QM", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-TC", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-JR", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-LR", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-SF", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.CZCE + "-SM", { Time: 0, Decimal: 0 }],
      //中期所
      [MARKET_SUFFIX_NAME.CFFEX + "-TF", { Time: 1, Decimal: 3 }],
      [MARKET_SUFFIX_NAME.CFFEX + "-TS", { Time: 1, Decimal: 3 }],
      [MARKET_SUFFIX_NAME.CFFEX + "-IH", { Time: 2, Decimal: 1 }],
      [MARKET_SUFFIX_NAME.CFFEX + "-IC", { Time: 2, Decimal: 1 }],
      [MARKET_SUFFIX_NAME.CFFEX + "-IF", { Time: 2, Decimal: 1 }],
    ]),
    MAP_ONEWORD = new Map([
      //大连商品交易所
      [MARKET_SUFFIX_NAME.DCE + "-C", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.DCE + "-L", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.DCE + "-V", { Time: 0, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.DCE + "-A", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.DCE + "-B", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.DCE + "-M", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.DCE + "-Y", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.DCE + "-P", { Time: 3, Decimal: 0 }],
      [MARKET_SUFFIX_NAME.DCE + "-J", { Time: 3, Decimal: 1 }],
      [MARKET_SUFFIX_NAME.DCE + "-I", { Time: 3, Decimal: 1 }],
      //中期所
      [MARKET_SUFFIX_NAME.CFFEX + "-T", { Time: 1, Decimal: 3 }],
    ]);

  this.GetData = function (upperSymbol) {
    let oneWord = upperSymbol.charAt(0),
      twoWords = upperSymbol.substr(0, 2),
      oneWordName = null,
      twoWordsName = null;

    if (MARKET_SUFFIX_NAME.IsDCE(upperSymbol)) {
      //大连商品交易所
      oneWordName = MARKET_SUFFIX_NAME.DCE + "-" + oneWord;
      twoWordsName = MARKET_SUFFIX_NAME.DCE + "-" + twoWords;
    } else if (MARKET_SUFFIX_NAME.IsSHFE(upperSymbol)) {
      //上期所
      oneWordName = MARKET_SUFFIX_NAME.SHFE + "-" + oneWord;
      twoWordsName = MARKET_SUFFIX_NAME.SHFE + "-" + twoWords;
    } else if (MARKET_SUFFIX_NAME.IsCFFEX(upperSymbol)) {
      //中期所
      oneWordName = MARKET_SUFFIX_NAME.CFFEX + "-" + oneWord;
      twoWordsName = MARKET_SUFFIX_NAME.CFFEX + "-" + twoWords;
    } else if (MARKET_SUFFIX_NAME.IsCZCE(upperSymbol)) {
      //郑州期货交易所
      oneWordName = MARKET_SUFFIX_NAME.CZCE + "-" + oneWord;
      twoWordsName = MARKET_SUFFIX_NAME.CZCE + "-" + twoWords;
    }

    if (MAP_TWOWORDS.has(twoWordsName)) {
      return MAP_TWOWORDS.get(twoWordsName);
    }

    if (MAP_ONEWORD.has(oneWordName)) {
      return MAP_ONEWORD.get(oneWordName);
    }

    return null;
  };

  this.GetSplitData = function (upperSymbol) {
    let data = this.GetData(upperSymbol);
    if (!data) {
      return null;
    }

    return TIME_SPLIT[data.Time];
  };

  this.GetDecimal = function (upperSymbol) {
    let data = this.GetData(upperSymbol);
    if (!data) {
      return 2;
    }

    return data.Decimal;
  };
}

g_NYMEXTimeData = new NYMEXTimeData();
g_NYMEXTimeData = new COMEXTimeData();
g_NYMEXTimeData = new NYBOTTimeData();
g_NYMEXTimeData = new CBOTTimeData();
g_NYMEXTimeData = new LMETimeData();
g_NYMEXTimeData = new FuturesTimeData();

export {
  g_NYMEXTimeData,
  g_COMEXTimeData,
  g_NYBOTTimeData,
  g_CBOTTimeData,
  g_LMETimeData,
  g_FuturesTimeData,
  MARKET_SUFFIX_NAME,
};
